package com.app.megaprosoft.DB;

import java.sql.*;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ItemStock {	
	
	 Connect con = new Connect(); 
	 Connection conn = con.Connect();
	 ResultSet rs = null;
	 SQLiteDBClass myDb;
	 SQLiteDatabase db;
	 Context context;
	 private static final String TABLE_ItemStock = "_ItemStock";
	 public Context getContext() {
		return context;
	 }

	 public void setContext(Context context) {
		this.context = context;
	 }
	 
	private String ItemStockCode,ItemStockDesc,OperationType;
    
    public ItemStock(){ItemStockCode=ItemStockDesc=OperationType="";
    }

    public ItemStock( 
    		String ItemStockCode,
    		String ItemStockDesc,
    		String OperationType
    		)
    {
    	this.ItemStockCode = ItemStockCode;
    	this.ItemStockDesc = ItemStockDesc;
    	this.OperationType = OperationType;
    }
    
    public void closeConnecttion() throws Exception {
   	 if (conn != null) {
            conn.close();
        }
   }
    
    public void setOperationType(String OperationType)
	{
		this.OperationType = OperationType;
	}
    public void setItemStockCode(String ItemStockCode)
	{
		this.ItemStockCode = ItemStockCode;
	}
	public void setItemStockDesc(String ItemStockDesc)
	{
		this.ItemStockDesc = ItemStockDesc;
	}
	
	public String getOperationType()
	{
		return this.OperationType;
	}
	public String getItemStockCode()
	{
		return this.ItemStockCode;
	}
	public String getItemStockDesc()
	{
		return this.ItemStockDesc;
	}
	
	public ResultSet selectItemStock(String ProvinceCode) throws Exception {
		String StrSql   = "SELECT [ItemStockCode]"+
                		  		",[ItemStockDesc] "+		
                		  "FROM [dbo].[ItemStock] " ;
			     	

		return con.selectData(StrSql);
	 }
	
	public void DEFINE_ItemStock() {
		rs = null;
		myDb = new SQLiteDBClass(getContext());
		db = myDb.getWritableDatabase();

		try {
			rs = selectItemStock("");
			while (rs.next()) {
				ContentValues Val = new ContentValues();
				Val.put("ItemStockOID", rs.getString("ItemStockCode"));
				Val.put("ItemStockDesc", rs.getString("ItemStockDesc"));

				db.insert(TABLE_ItemStock, null, Val);
			}
		} catch (Exception e) {
			Log.d("TABLE_ItemStock", "Create Table not Successfully.");
		}finally{
			try {
				closeConnecttion();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		Log.d("TABLE_ItemStock", "Create Table Successfully.");
		db.close();
	}
	
	
}
